package com.ruoyi.medical.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.MatchException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import com.ruoyi.medical.mapper.RegistrationMapper;
import com.ruoyi.medical.domain.Registration;
import com.ruoyi.medical.service.IRegistrationService;

import javax.annotation.Resource;

/**
 * 挂号信息管理Service业务层处理
 *
 * @author ruoyi
 * @date 2024-02-26
 */
@Service
public class RegistrationServiceImpl implements IRegistrationService {
    @Resource
    private RegistrationMapper registrationMapper;

    /**
     * 查询挂号信息管理
     *
     * @param id 挂号信息管理主键
     * @return 挂号信息管理
     */
    @Override
    public Registration selectRegistrationById(Long id) {
        return registrationMapper.selectRegistrationById(id);
    }

    /**
     * 查询挂号信息管理列表
     *
     * @param registration 挂号信息管理
     * @return 挂号信息管理
     */
    @Override
    public List<Registration> selectRegistrationList(Registration registration) {
        return registrationMapper.selectRegistrationList(registration);
    }

    /**
     * 新增挂号信息管理
     *
     * @param registration 挂号信息管理
     * @return 结果
     */
    @Override
    public int insertRegistration(Registration registration){
        registration.setCreateTime(DateUtils.getNowDate());
        //CreateBy
        String username = SecurityUtils.getUsername();
        if (StringUtils.isEmpty(username)) {
            throw new RuntimeException("用户名不存在");
        } else {
            registration.setCreateBy(username);
        }
        return registrationMapper.insertRegistration(registration);
    }

    /**
     * 修改挂号信息管理
     *
     * @param registration 挂号信息管理
     * @return 结果
     */
    @Override
    public int updateRegistration(Registration registration) {
        registration.setUpdateTime(DateUtils.getNowDate());
        //UpdateBy
        String username = SecurityUtils.getUsername();
        if (StringUtils.isEmpty(username)) {
            throw new RuntimeException("用户名不存在");
        } else {
            registration.setUpdateBy(username);
        }
        return registrationMapper.updateRegistration(registration);
    }

    /**
     * 批量删除挂号信息管理
     *
     * @param ids 需要删除的挂号信息管理主键
     * @return 结果
     */
    @Override
    public int deleteRegistrationByIds(Long[] ids) {
        return registrationMapper.deleteRegistrationByIds(ids);
    }

    /**
     * 删除挂号信息管理信息
     *
     * @param id 挂号信息管理主键
     * @return 结果
     */
    @Override
    public int deleteRegistrationById(Long id) {
        return registrationMapper.deleteRegistrationById(id);
    }

}
